package com.qf;

import com.qf.conf.RibbonConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.netflix.ribbon.RibbonClients;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
//启用eureka客户端
@EnableEurekaClient
//配置指定服务的ribbon负载均衡策略
//@RibbonClients
@RibbonClient(value = "QF-ORDER",configuration = RibbonConfig.class)
//开启服务保护
@EnableCircuitBreaker
//开启feign接口扫描
@EnableFeignClients(basePackages = "com.qf.feigns")
public class QFUserApplication {

    public static void main(String[] args) {
        SpringApplication.run(QFUserApplication.class, args);
    }


    /**
     * 这个对象可以实现http请求的发送
     * @return
     */
    @Bean
    @LoadBalanced //这个注解会向RestTemplate中添加一个LoadBalancerInterceptor.在这个对象内部会基于LoadBalancerClient实现实例负载均衡选择
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

}
